package com.jbm.jbmsupplier.activity.register.mode

import com.jbm.enterapplication.InterfaceMa
import com.jbm.enterapplication.utlisclass.HttpNet
import com.jbm.onehome.iface.IVerifyCode
import com.jbm.onehome.iface.Login
import rx.Observable
import rx.Observer

/**
 * Created by 家帮忙 on 2017/8/22.
 */
class Regiter_Mode_User_WX: Reginster_UsertInter_WX<String> {
    override fun GainRegisterIntergace(phont: String, validate: String, loginid: String, sex: String, name: String, handler: String, oclicklist: InterfaceMa<String>) {
        HttpNet.getInstans().obsevice(Observable.create(Observable.OnSubscribe<Login> { obVersion ->
            obVersion.onNext(HttpNet.getInstans().getOhInter().RegistCustomer(0, phont, "", "", validate,0, loginid,name, Integer.parseInt(sex),handler,""))
        })).subscribe(object :Observer<Login>{
            override fun onNext(t: Login?) {
                if (t?.m_code == 200) {
                    //搭桥成功
                    oclicklist.onSuccess("",true)
                } else if (t?.m_info == "time out") {
                    oclicklist.onSuccess(t.m_info,false)
                    //搭桥超时


                } else if (t?.m_code == 500) {
                    oclicklist.onSuccess(t.m_info,false)
                    //搭桥失败


                } else {
                    oclicklist.onSuccess(t!!.m_info,false)

                }
            }

            override fun onError(e: Throwable?) {
            }

            override fun onCompleted() {
            }

        })
    }



    override fun GainValidateCode(validate: String, oclicklist: InterfaceMa<String>) {
        if (!validate.equals("")) {
            HttpNet.getInstans().obsevice(Observable.create(Observable.OnSubscribe<IVerifyCode> { obVersion ->
                obVersion.onNext(HttpNet.getInstans().getOhInter().CreateVCode(validate, "reg_user"))
            })).subscribe(object :Observer<IVerifyCode>{
                override fun onCompleted() {

                }
                override fun onNext(t: IVerifyCode?) {
                    if (t?.m_code==200){
                        oclicklist.onSuccess("",true)

                    } else if (t?.m_info == "time out") {
                        oclicklist.setError(t.m_info,false)
                        //手机号获取验证码超时

                    } else if (t?.m_code == 500) {
//                        手机号获取验证码失败
                        oclicklist.setError(t.m_info,false)
                    } else {
                        //手机号获取验证码失败
                        oclicklist.setError(t!!.m_info,false)
                    }
                }

                override fun onError(e: Throwable?) {
                    oclicklist.setError("请求接口错误"+e,false)

                }

            })

        }


    }




}